Szjmjkdallqx = Ext.extend(Ext.Window,{
	selectPanel : null,
	constructor : function(ygid){
		this.initPanel(ygid);
		Szjmjkdallqx.superclass.constructor.call(this,{
			title : '设置居民健康档案浏览权限',
			modal : true,
			buttonAlign : "center", //按钮居中
			width : 650,
			height : 420,
			autoScroll : true,
			constrain : true,
			maximizable : true,
			layout : 'border',
			items : this.selectPanel,
			buttons : [{
				text : "确认",
				iconCls : "btn-ok",
				scope : this,
				handler : function(){
					this.submit(ygid)
				}
			}, {
				text : "关闭",
				iconCls : "btn-cancel",
				scope : this,
				handler : this.close
			}]
		})
	},
	submit : function(ygid){
		var self = this;
		var selectedGrid = Ext.getCmp('selectedGrid');
		var selectStore = selectedGrid.getStore();
		var functionIds = "";
		selectStore.each(function(record){
			functionIds += (record.get('functionId')+",");
		});
		Ext.Ajax.request({
			method : 'POST',
			url : '../../health/jmjkdallqxSave.do',
			params : {
				functionIds : functionIds,
				ygid : ygid
			},
			success : function(response){
				var result = Ext.decode(response.responseText);
				if(result.success){
					Ext.ux.Toast.msg('提示信息','保存成功!');
					self.close();
				}else{
					Ext.ux.Toast.msg('提示信息','保存失败，请联系管理员!');
				}
			},
			failure : function(form, action) {
				Ext.ux.Toast.msg('提示信息','保存失败，请联系管理员!');
			}
		})
	},
	initPanel : function(ygid){
		var self = this;
		var y = new Ext.FormPanel({
					id : "selectorSearchPanel",
					height : 38,
					region : "north",
					layout : "hbox",
					bodyStyle : "padding:6px 2px 2px 2px;",
					layoutConfigs : {
						align : "middle"
					},
					defaultType : "label",
					defaults : {
						margins : "4 4 4 4"
					},
					items : [{
								text : "功能名称"
							}, {
								xtype : "textfield",
								name : "functionName",
								width : 260,
								maxLength : 256
							}, {
								xtype : "button",
								text : "查询",
								iconCls : "icon-search",
								scope : this,
								handler : this.search
							}]
				});
		var x = new Ext.grid.CheckboxSelectionModel();
		var q = new Ext.grid.ColumnModel({
			columns : [x, new Ext.grid.RowNumberer(), {
				header : "功能名称",
				dataIndex : "functionName"
			}]
		});
		var s = new Ext.grid.CheckboxSelectionModel();
		var p = new Ext.grid.GridPanel({
					title : "浏览权限",
					autoScroll : true,
					id : "contactGrid",
					region : "west",
					width : 300,
					autoWidth : false,
					store : new Ext.data.ArrayStore({
						fields : ["functionId","functionName"]
					}),
					shim : true,
					trackMouseOver : true,
					disableSelection : false,
					loadMask : true,
					cm : q,
					sm : x,
					viewConfig : {
						forceFit : true,
						enableRowBody : false,
						showPreview : false
					}
				});
		p.on("rowdblclick", function(f, j, k) {
			self.addAll();
		});
		var b = new Ext.Panel({
					region : "center",
					frame : true,
					width : 30,
					layout : {
						type : "vbox",
						pack : "center",
						align : "stretch"
					},
					defaultType : "button",
					items : [{
						iconCls : "add-all",
						text : "",
						scope : this,
						handler : this.addAll
					}, {
						iconCls : "rem-all",
						text : "",
						scope : this,
						handler : this.removeAll
					}]
		});
		var z = new Ext.grid.GridPanel({
					id : "selectedGrid",
					title : "已选权限",
					layout : "form",
					region : "east",
					width : 300,
					height : "100%",
					autoScroll : true,
					border : false,
					viewConfig : {
						forceFit : true,
						enableRowBody : false,
						showPreview : false
					},
					store : new Ext.data.ArrayStore({
								fields : ["functionId", "functionName"]
							}),
					trackMouseOver : true,
					sm : s,
					columns : [s, new Ext.grid.RowNumberer(), {
								header : "功能名称",
								dataIndex : "functionName"
							}]
				});
		z.addListener("rowdblclick", function(c, a) {
			self.removeAll();
		});
		this.selectPanel = new Ext.Panel({
			layout : "border",
			region : 'center',
			border : false,
			anchor : "100%,100%",
			items : [y,p, b]
		});
		this.selectPanel.add(z);
		this.selectPanel.doLayout();
		Ext.Ajax.request({
			method : 'POST',
			url : '../../health/getJkdallqx.do',
			params : {
				ygid : ygid
			},
			success : function(response) {
				var result = Ext.decode(response.responseText);
				if(result.success){
					var qxgnList = result.qxgnList;
					var hasChooseList = result.hasChooseList;
					var Record = p.getStore().recordType;
					for(var i = 0;i < qxgnList.length;i++){
						var record = new Record();
    					record.set("functionId",qxgnList[i].functionId);
    					record.set("functionName",qxgnList[i].functionName);
    					p.getStore().add(record);
					}
					for(var i = 0;i < hasChooseList.length;i++){
						var record = new Record();
    					record.set("functionId",hasChooseList[i].functionId);
    					record.set("functionName",hasChooseList[i].functionName);
    					z.getStore().add(record);
					}
				}else{
					Ext.ux.Toast.msg('提示信息','加载失败，请联系管理员!');
				}
			},
			failure : function(form, action) {
				Ext.ux.Toast.msg('提示信息','加载失败，请联系管理员!');
			}
		});
	},
	addAll : function(){
		var i = Ext.getCmp("contactGrid");
		var d = Ext.getCmp("selectedGrid");
		var h = d.getStore();
		var c = i.getSelectionModel().getSelections();
		for (var a = 0; a < c.length; a++) {
			var n = c[a].data.functionId;
			var g = c[a].data.functionName;
			var l = false;
			for (var b = 0; b < h.getCount(); b++) {
				if (h.getAt(b).data.functionId == n) {
					l = true;
					break;
				}
			}
			if (!l) {
				var e = {
					functionId : n,
					functionName : g
				};
				var m = new h.recordType(e);
				h.add(m);
			}
		}
	},
	removeAll : function(){
		var c = Ext.getCmp("selectedGrid");
		var e = c.getStore();
		var b = c.getSelectionModel().getSelections();
		for (var d = 0; d < b.length; d++) {
			e.remove(b[d]);
		}
	},
	search : function(){
		var searchPanel = Ext.getCmp('selectorSearchPanel');
		var values = searchPanel.getForm().getValues();
		var contactGrid = Ext.getCmp("contactGrid");
		contactGrid.getStore().filter('functionName',values.functionName);
	}
});
	
